package edu.shiep.sunyu.model;

import com.mongodb.MongoClient;

public class DBClient {

	public DBClient() {
			
	}
	
	public boolean connect() {
		boolean success = false;
		try {
			_mongo = new MongoClient("localhost", 27017);
			success = true;
		}
		catch (Exception e) {
			System.out.println("Can't connect to local host mongodb.");
		}
		
		return success;
	}
	
	public void disconnect() {
		if (_mongo != null) {
			_mongo.close();
			_mongo = null;
		}
	}
	
	public Database getDB(String name) {
		return new Database(_mongo.getDB(name));
	}
	
	private MongoClient _mongo = null;

}
